import apiPath from '@/common/apiPath.js'
const request = (url = '', data = {}, type = 'GET', header = {}) => {

	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '加载中',
			mask: true
		});
		uni.request({
			method: type,
			url: url,
			data: data,
			header: {
				"content-type": 'application/json;charset=utf-8',
			},
			dataType: 'json',
		}).then((response) => {
			uni.hideLoading();
			const {
				statusCode,
				code,
				data
			} = response;

			if ((statusCode > 199 && statusCode < 300) || code == 0) {
				resolve(data);
			} else {
				uni.showToast({
					title: '错误',
					icon: "error"
				})
				reject({
					meaasge: '？？？'
				})
			}
		}).catch(error => {

			uni.showToast({
				title: error.errMsg,
				icon: "error"
			})

			setTimeout(function() {
				uni.hideLoading();
			}, 100);
			console.log(error)
			reject(error)
		})
	});
}
export default request